﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Per_pixel_OCR
{
    public static class Extensions
    {
        public static int MaxIndex(this double[] sequence)
        {
            int maxIndex = 0;
            double maxValue = sequence[0];

            for (int i = 1; i < sequence.Length; i++)
            {
                if (sequence[i] > maxValue)
                {
                    maxValue = sequence[i];
                    maxIndex = i;
                }
            }

            return maxIndex;
        }

        public static int MaxIndex(this int[] sequence)
        {
            int maxIndex = 0;
            int maxValue = sequence[0];

            for (int i = 1; i < sequence.Length; i++)
            {
                if (sequence[i] > maxValue)
                {
                    maxValue = sequence[i];
                    maxIndex = i;
                }
            }

            return maxIndex;
        }

        public static Pixel[] GetPixels(this Digit[] digits)
        {
            List<Pixel> rVal = new List<Pixel>();

            for (int i = 0; i < digits.Length; i++)
            {
                rVal.AddRange(digits[i].NonZeroPixels);
            }

            return rVal.ToArray();
        }
        
        public static void Add(this double[] histogram, double[] temp)
        {
            for (int i = 0; i < histogram.Length; i++)
            {
                histogram[i] += temp[i];
            }
        }
    }
}
